import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-02-06
 * Time: 20:42
 */
class Img implements Comparator<Integer> {
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}

public class Test {
    class Solution {

        public int[] smallestK(int[] arr, int k) {
            PriorityQueue<Integer> priorityQueue=new PriorityQueue<>(new Img());
            for (int i = 0; i < k; i++) {
                priorityQueue.offer(arr[i]);
            }
            for (int i = k; i < arr.length; i++) {
                if(arr[i]<priorityQueue.peek()){
                    priorityQueue.poll();
                    priorityQueue.offer(arr[i]);
                }
            }
            int[] tmp=new int[k];
            for (int i = 0; i < k; i++) {
                tmp[i]=priorityQueue.poll();

            }
       return tmp;
        }
    }

}
